<?php
/**
 *  wap站
 */

require_once('../common.inc.php');
loadconf('mobileapi/base');

use MobileApi\AppInfo;

class index extends lib\core\Action
{
    public function doDefault()
    {
        $smarty = $this->app->page();

        $smarty->output();
    }


    public function doDownload()
    {
        //header("Location: http://a.app.qq.com/o/simple.jsp?pkgname=com.qbaobei.meite");
        //exit;
        $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
        if (strpos($agent, 'micromessenger') !== false && strpos($agent, 'iphone') === false && strpos($agent, 'ipad') === false) {
            $smarty = $this->app->page();
            $smarty->output('mobile/link-android.tpl');
            exit;
        }

        $appid = $this->getSystem();
        $version = AppInfo::getVersion($appid);
        $url = $version['Url'];
        header("Location: " . $url);
    }

    // 获取用户系统
    private function getSystem()
    {
        $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
        $type = trim($_GET['version']);

        $app_id = MOBILE_APPID_ANDROID;
        if (strpos($agent, 'iphone') !== false || strpos($agent, 'ipad') !== false || $type === 'ios') {
            $app_id = MOBILE_APPID_IPHONE;
        }

        return $app_id;
    }
}

$app->run();
